/*--------------------------步行模块------------------------------*/

export default function walk(target){
  // 显示目标点位
  showPoint()
  // 获取移动距离
  const from=player.position.clone()
  const to = target.clone();
  from.y=0
  to.y=0

  distance = from.distanceTo(to);
  
  // 获取移动方向
  targetNorm = new THREE.Vector3().subVectors(to, from).normalize();

  // 移动动画 
  walking = true
  console.log('walking',walking)
  action.idle.stop();
  action.walking.play();
}
// 点位效果
function showPoint(){
  let point=  scene.getObjectByName("point");
  if(point){
    return point.position.set(target.x,target.y,target.z);
  }
  
 let geometry = new THREE.CircleGeometry(.1,100);
  const mat = new THREE.MeshBasicMaterial({
    color: 0x00ffff,
    side: THREE.DoubleSide,
  });

  const test = new THREE.Mesh(geometry, mat);
  test.rotateX(Math.PI*(0.5))

  test.name = "point";

  test.position.set(target.x,target.y+0.01,target.z);
  scene.add(test);
}

